package org.gd.hellojson.jackson.formatter;

import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;

import java.io.*;
import java.net.URL;
import java.util.Map;
import java.util.TreeMap;

import static org.codehaus.jackson.map.SerializationConfig.Feature.SORT_PROPERTIES_ALPHABETICALLY;

/**
 * @author Gorhover
 * @version 1.0-SNAPSHOT
 * @since 2013-10-01 15:11
 */
class App {

    public static void main(String[] args) throws IOException {
        InputStream inputStream = null;
        try {
            ObjectMapper mapper = new ObjectMapper();
            inputStream = json().openStream();
            Object json =  mapper.readValue(inputStream, new TypeReference<Object>() {});
            mapper.configure(SORT_PROPERTIES_ALPHABETICALLY, true);
            mapper.writerWithDefaultPrettyPrinter().writeValue(System.out, json);
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
        }
    }

    static URL json() {
        return App.class.getClassLoader().getResource("test.json");
    }
}
